//
// Created by francklinson on 2021/10/21 AT 11:12.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>

using namespace std;

class Solution {
public:
    int findMiddleIndex(vector<int> &nums) {
        int sum = accumulate(nums.begin(), nums.end(), 0);
        int preSum = 0;
        for (int i = 0; i < nums.size(); ++i) {
            if (preSum * 2 + nums[i] == sum)
                return i;
            preSum += nums[i];
        }
        return -1;
    }
};

int main() {
    vector<int> nums{2, 3, -1, 8, 4};
    Solution solution;
    cout << solution.findMiddleIndex(nums) << endl;
    return 0;
}

